define(function(require, exports, module){
	require("resource/js/easyui/themes/icon.css");
	require("resource/js/easyui/easyloader.js");
	var AJAX = require("resource/js/component/ajax.js");
	var EUtil = require("resource/js/component/easyutil.js");
		var dgutil = undefined;
	var config = {
		name:"沥青拌合站信息表",
		column:[[
			{field:'id',title:'主键ID',width:100,align:'center',height:50,hidden:true},
		
			{field:'sectionId',title:'标段ID',width:100,align:'center',height:50,hidden:true},
		
			{field:'projectNo',title:'项目编码',width:100,align:'center',height:50,hidden:true},
		
			{field:'sectionNo',title:'标段编码',width:100,align:'center',height:50,hidden:true},
		
			{field:'stationNo',title:'拌合站编码',width:100,align:'center',height:50,hidden:true},
		
			{field:'deviceName',title:'设备名称',width:100,align:'center',height:50,hidden:false},
		
			{field:'codeNum',title:'全路径编码',width:100,align:'center',height:50,hidden:false},
		
			{field:'deviceCode',title:'设备号',width:100,align:'center',height:50,hidden:true},
		
			{field:'frd',title:'RFID设备',width:100,align:'center',height:50,hidden:false},
		
			{field:'sn',title:'sn',width:100,align:'center',height:50,hidden:false},
		
			{field:'plannedTotal',title:'计划总产量(吨)',width:100,align:'center',height:50,hidden:false},
		
			{field:'producedTotal',title:'已经生产总量',width:100,align:'center',height:50,hidden:true},
		
			{field:'updateDate',title:'最近更新时间',width:100,align:'center',height:50,hidden:true},
		
			{field:'updateUser',title:'最近更新人',width:100,align:'center',height:50,hidden:true},
		]]
	}
	
	var initpage = function(){
		var sectionId = sessionStorage.getItem('sectionId');  //获取标段id
		$("#searchSectionId").val(sectionId);
		dgutil = EUtil.ajaxDataGrid(datagridconfig);

	/*	AJAX.init().success(function(code,msg,data){

		}).error(function(code,msg,data){

		}).contentType('application/json').post(BASEPATH+"/dcs/paverConstructionAction/queryRealTimeTrajectory.htm",{sectionId:"190402145423000012",isFirst:"0"});
*/
	}
	var initFiledByForm = function(rows,id){
		var validate = true;
		if(typeof rows == "boolean"){
			validate = rows;
		}
	}

	var addDialogInit = function(url){
		$("#editdlg").dialog({
			title:config.name+"增加",
			href:url,
			onLoad:function(){
				initFiledByForm(false,'add');
		    },
			buttons: [{
				text:'保存',
				iconCls:'icon-ok',
				accessKey:{akey:18,mkey:83},
				handler:function(){
					using(["form"],function(){
						if($("#editform").form("validate")){
							var sectionId = sessionStorage.getItem('sectionId');  //获取标段id
							if(sectionId == null || sectionId == undefined){
								sectionId = '001';
							}
							var obj = $("#editform").serializeJson();
							obj.sectionId = sectionId;
							obj.codeNum = obj.projectNo+"-"+obj.sectionNo+"-"+obj.stationNo;
							AJAX.init().success(function(code,msg,data){
								$.messager.show({ title:"系统提示", msg:msg, timeout:2000, showType:'slide' });
								dgutil.pager();
								$("#editdlg").dialog("close");
		    	    		}).error(function(code,msg,data){
		    	    			$.messager.alert("系统提示", msg, "error");
		    	    		}).contentType('application/json').post(BASEPATH+"/dcs/asphalt/station/saveMixAsphaltStation.htm",JSON.stringify(obj));
						}
					});
				}
			},{
				text:'取消',
				addClass:'l-btn-red',iconCls:'icon-not',
				accessKey:{akey:18,mkey:67},
				handler:function(){
					$('#editdlg').dialog('close');
				}
			}]
		});
		$("#editdlg").dialog("open");
	}
	var updDialogInit = function(url,row){
		$("#editdlg").dialog({
			iconCls: 'icon-save',
			title:config.name+'修改',
			href:url,
			onLoad:function(){
				initFiledByForm(row,'upd');
				$("#editform").form("load",row);
		    },
			buttons: [{
				text:'保存',
				iconCls:'icon-ok',
				accessKey:{akey:18,mkey:83},
				handler:function(){
					using(["form"],function(){
						if($("#editform").form("validate")){
							var sectionId = sessionStorage.getItem('sectionId');  //获取标段id
							if(sectionId == null || sectionId == undefined){
								sectionId = '001';
							}
							var obj = $("#editform").serializeJson();
							obj.sectionId = sectionId;
							obj.codeNum = obj.projectNo+"-"+obj.sectionNo+"-"+obj.stationNo;
							AJAX.init().success(function(code,msg,data){
								$.messager.show({ title:"系统提示", msg:msg, timeout:2000, showType:'slide' });
								dgutil.pager();
								$("#editdlg").dialog("close");
		    	    		}).error(function(code,msg,data){
		    	    			$.messager.alert("系统提示", msg, "error");
		    	    		}).contentType('application/json').post(BASEPATH+'/dcs/asphalt/station/updateMixAsphaltStation.htm',JSON.stringify(obj));
						}
					});
				}
			},{
				text:'取消',
				addClass:'l-btn-red',iconCls:'icon-not',
				accessKey:{akey:18,mkey:67},
				handler:function(){
					$('#editdlg').dialog('close');
				}
			}]
		});
		$("#editdlg").dialog("open");
	}
	var delInit = function(url,row){
		/**
		 * 刪除操作校驗是否存在繳伴擠
		 */
		AJAX.init().success(function(code,msg,data){
            if(data > 0){
                $.messager.show({ title:"系统提示", msg:"请解绑拌合站下设备", timeout:2000, showType:'slide' });
            }else{
                 EUtil.ajaxHandler(url,{checkeds:row.id},function(){
                     dgutil.pager();
                });
            }
		}).error(function(code,msg,data){
		}).post(BASEPATH+'/dcs/asphalt/device/queryAsphaltStationDel.htm?blenderId='+row.id);

		/*var checks = [];
		for(var key in rows){
			var id = '' +rows[key].id;
			checks.push(id);
		}
		EUtil.ajaxHandler(url,{checkeds:checks.join(",")},function(){
			dgutil.delRow(rows);
		});*/
	}
	
	//拌合参数设置
	function toParamDialogInit(baseUrl,row){
		$("#paramdlg").dialog({
			href:baseUrl,
			onLoad: function () {
			}
		});
		$("#searchform").form("load",row);
		$("#stationId_search").val(row.id);
		$("#paramdlg").dialog("open");
	}
	
	module.exports = {
		trans:function(){
			var buttons ={ 
				title:{
					_class:"",
					text:"设备管理"
				},
				btn:[
//					 {
//						 iconCls: 'icon-search',
//						 url:'/dcs/asphalt/station/queryMixAsphaltStationByPage.htm',
//						 text:"查询",
//						 //addClass:'l-btn-display',
//						 btnType: 'searchBtn',
//						 handler: function(){dgutil.pager(1);}
//					 },
					 {
						 iconCls: 'icon-add',
						// addClass:'l-btn-display',
						 text:"添加",
						 url:'/view/dcs/asphalt/station/mixasphaltstationadd',
						 handler: addDialogInit
					 },
					 {
						 iconCls: 'icon-edit',
						 url:'/view/dcs/asphalt/station/mixasphaltstationupd',
						 text:"修改",
						// addClass:'l-btn-display',
						 needRow:true,
						 handler: updDialogInit
					 },
					 {
						 iconCls: 'icon-remove',
						 url:'/dcs/asphalt/station/deleteMixAsphaltStation.htm',
						 text:"删除",
						// addClass:'l-btn-display',
						 needRow:true,
						 isCheck:true,
						 handler: delInit
					 },
					 {
						iconCls:"icon-edit",
						text:"拌合参数设置",
						/*addClass:"l-btn-display",*/
						url:"/view/dcs/asphalt/station/blenderParamters",
						needRow:true,
						handler:toParamDialogInit
					}
				]};
			datagridconfig = {
				fitColumns:true,
				singleSelect:false,
				striped:true,
				autoRowHeight:false,
				fit: true,
				toolbar:buttons,
				columns:config.column,
				eid:"dg",
				url:BASEPATH+'/dcs/asphalt/station/queryMixAsphaltStationByPage.htm',
				args:"searchform"
			};
			
			using(["parser","dialog","datagrid","combobox" ],function(){
				initpage();
			});
		}
	}
});
